package com.hkfn.rfb.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.bean.BannerModel;
import com.hkfn.rfb.common.utils.StringUtils;

public class MultipleChooseListAdapter extends BaseRecyclerAdapter<BannerModel> {

    private Context context;

    public MultipleChooseListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_choose_list, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, BannerModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private LinearLayout ll_item_content;
        private TextView tv_title;
        private TextView tv_vice_title;

        public MyViewHolder(View itemView) {
            super(itemView);
            ll_item_content = itemView.findViewById(R.id.ll_item_content);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_vice_title = itemView.findViewById(R.id.tv_vice_title);
        }
    }

    private void setItemData(MyViewHolder viewHolder, BannerModel data, int realPosition) {
        viewHolder.tv_title.setText(data.getTitle());
        if (StringUtils.isEmpty(data.getViceTitle())){
            viewHolder.tv_vice_title.setVisibility(View.GONE);
        }else {
            viewHolder.tv_vice_title.setVisibility(View.VISIBLE);
            viewHolder.tv_vice_title.setText(data.getViceTitle());
        }
        if ("1".equals(data.getActionValue())){
            viewHolder.tv_title.setTextColor(context.getResources().getColor(R.color.main_color));
            viewHolder.tv_vice_title.setTextColor(context.getResources().getColor(R.color.main_color_tran_half));
            viewHolder.ll_item_content.setBackground(context.getResources().getDrawable(R.drawable.shape_main_color_tran_bg_frame));
        }else {
            viewHolder.tv_title.setTextColor(context.getResources().getColor(R.color.text_color));
            viewHolder.tv_vice_title.setTextColor(context.getResources().getColor(R.color.hint_text_color));
            viewHolder.ll_item_content.setBackground(null);
        }
    }
}
